package io.zhengsh.order.mapper;

import io.zhengsh.order.dto.QueryOrderPageDto;
import io.zhengsh.order.entity.OrderEntity;


import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderEntityMapper {


    @Insert("insert into t_order (`order_code`) values(#{orderCode})")
    @Options(useGeneratedKeys = true, keyProperty = "oid", keyColumn = "oid")
    int insertSelective(OrderEntity record);

    @Select("select * from t_order where oid = #{oid}")
    OrderEntity selectOne(@Param("oid") Long oid);

    @Select("select * from t_order where 1=1 " +
            "<if test=\"#{orderCode} != null and #{orderCode} != ''\">" +
            "  order_code = #{orderCode} " +
            "</if>" +
            "order by id desc limit ${(page-1) * limit},${limit}")
    List<OrderEntity> query(QueryOrderPageDto orderPageDto);

    @Select("select count(*) from t_order where 1=1 " +
            "<if test=\"#{orderCode} != null and #{orderCode} != ''\">" +
            "  order_code = #{orderCode} " +
            "</if>" +
            " order_code = #{orderCode}")
    Long count(QueryOrderPageDto orderPageDto);
}